package com.bishe.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bishe.entity.ClaTeacher;
import com.bishe.entity.resp.CommonPageRequest;
import com.bishe.entity.resp.CommonSortOrderEnum;
import com.bishe.entity.resp.PageParam;
import com.bishe.mapper.ClaTeacherMapper;
import com.bishe.service.ClaTeacherService;
import org.springframework.stereotype.Service;

/**
* @author wwz
* @description 针对表【cla_teacher】的数据库操作Service实现
* @createDate 2024-04-03 23:14:54
*/
@Service
public class ClaTeacherServiceImpl extends ServiceImpl<ClaTeacherMapper, ClaTeacher>
    implements ClaTeacherService {

    @Override
    public Page<ClaTeacher> page(PageParam pageParam) {
        QueryWrapper<ClaTeacher> queryWrapper = new QueryWrapper<>();

        if (ObjectUtil.isAllNotEmpty(pageParam.getSearchKey(), pageParam.getSearchValue())) {
            queryWrapper.eq(true, StrUtil.toUnderlineCase(pageParam.getSearchKey()), pageParam.getSearchValue());
        }

        if(ObjectUtil.isAllNotEmpty(pageParam.getSortField(), pageParam.getSortOrder())) {
            CommonSortOrderEnum.validate(pageParam.getSortOrder());
            queryWrapper.orderBy(true, pageParam.getSortOrder().equals(CommonSortOrderEnum.ASC.getValue()),
                    StrUtil.toUnderlineCase(pageParam.getSortField()));
        } else {
            queryWrapper.lambda().orderByAsc(ClaTeacher::getId);
        }
        return this.page(CommonPageRequest.defaultPage(), queryWrapper);
    }
}




